using System.Text;
using Common.Commands.AttachmentCommands;
using Common.Enumerations;
using Common.Views;
using Core.Domain.Model;
using NUnit.Framework;
using Sanelib.Common.Extensions;
using Sanelib.Common.Helpers;
using Sanelib.DataView;

namespace IntegrationTests.Processors
{
    public class AttachmentProcessorTester : IntegrationTestBase
    {
        [Test]
        public void ShouldAddAttachment()
        {
            var command = new AddAttachment
            {
                Id = GuidComb.New(),
                Name = "SanelibAccounts",
                FileType = "image/png",
                FileSize = 10,
                FileHashCode = "gsdhf35989fsnl1324ywefnj",
                FileData = Encoding.ASCII.GetBytes(ImageUtility.NoImageData), 
                ImageData = ImageUtility.NoImageData,
                EntityType = EntityType.Account,
                ReferenceId = GuidComb.New(),
                ReferenceName = "account",
                Description = ""
            };

            ProcessCommand(command);
            var repo = GetInstance<IViewRepository<AttachmentView>>();
            var attachmentView = repo.GetById(command.Id);

            Assert.AreEqual(command.Name, attachmentView.Name);
        }

        [Test]
        public void ShouldDeleteAttachment()
        {
            var attachment = new Attachment
            {
                Id = GuidComb.New(),
                Name = "SanelibAccounts",
                FileType = "image/png",
                FileSize = 10,
                FileHashCode = "gsdhf35989fsnl1324ywefnj",
                FileData = Encoding.ASCII.GetBytes(ImageUtility.NoImageData), 
                ImageData = ImageUtility.NoImageData,
                EntityType = EntityType.Account,
                ReferenceId = GuidComb.New(),
                ReferenceName = "account",
                Description = "This file for Account of sanelib"
            };
            Persist(attachment);

            var command = new DeleteAttachment(attachment.Id);
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<AttachmentView>>();
            var attachmentView = repo.GetById(command.Id);

            Assert.IsNull(attachmentView);
        }

        [Test, Explicit]
        public void ShouldUpdateAttachment()
        {
            var attachment = new Attachment
            {
                Id = GuidComb.New(),
                Name = "SanelibAccounts",
                FileType = "image/png",
                FileSize = 10,
                FileHashCode = "gsdhf35989fsnl1324ywefnj",
                FileData = Encoding.ASCII.GetBytes(ImageUtility.NoImageData), 
                ImageData = ImageUtility.NoImageData,
                EntityType = EntityType.Account,
                ReferenceId = GuidComb.New(),
                ReferenceName = "Account",
                Description = "This file for Account of sanelib"
            };
            Persist(attachment);

            var command = new UpdateAttachment
            {
                Id = attachment.Id,
                Name = "SanelibAccounts",
                ImageData = ImageUtility.NoImageData,
                Description = "This file for sanelib member bank account details."
            };
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<AttachmentView>>();
            var attachmentView = repo.GetById(command.Id);

            Assert.AreEqual(attachmentView.Id, attachment.Id);
            Assert.AreNotEqual(attachmentView.Description, attachment.Description);
        }
    }
}